package com.cseg674.dataquery.authentication;

import java.util.Properties;
import java.sql.ResultSet;
import java.sql.SQLException;


public class SignIn {

  private final static String sql = "SELECT * FROM UI WHERE username=? AND password = ?";

  private String action = null;
  private String username = null;
  private String password = null;

  public String getAction() {
    return action;
  }

  public void setAction(String action) {
    this.action = action;
  }

  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public boolean validate() {
    if (username == null || username.length() <= 0)
      return false;

    if (password == null || password.length() <= 0)
      return false;

    return true;
  }

  public boolean SignIn() {
    boolean check = false;
    Mysql mysql = new Mysql(sql);
    try {
      mysql.setString(1, username);
      mysql.setString(2, password);
      ResultSet rs = mysql.executeQuery();
      
      if (rs.next()) {
        check = true;
      }
    } catch (Exception e) {
      System.err.println(e);
    }
    finally {
      mysql.close();
      mysql = null;
    }
    return check;
  }

}